package com.zlp.stack;

import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

/**
 * 演示弱引用
 * -Xmx20m -XX:+PrintGCDetails -verbose:gc
 */
public class WeakReferenceDemo_1 {
    private static int _4MB = 1024 * 1024 * 4;
    public static void main(String[] args) throws IOException {

        List<WeakReference<byte[]>>list = new ArrayList<>();
        for (int i=0;i<10;i++){
            WeakReference<byte[]> wRef = new WeakReference<>(new byte[_4MB]);
            list.add(wRef);
            for (WeakReference w:list){
                System.out.print(w.get()+" ");
            }
            System.out.println();
            System.in.read();
        }
        System.out.println("循环结束。。。。。" + list.size());
    }
}
